package com.shaozi.nc.io.mq;

import org.apache.log4j.Logger;

import com.shaozi.data.mq.protocol.ConnectionBuilder;
import com.shaozi.data.mq.protocol.stomp.StompTextProducer;
import com.shaozi.nc.data.model.OrgPushMsgModel;
import com.shaozi.utils.data.ObjUtils;

public class OrgPushMsgProducer extends StompTextProducer {

	private final Logger logger = Logger.getLogger(OrgPushMsgProducer.class);

	public OrgPushMsgProducer(ConnectionBuilder connBuilder) {
		super(connBuilder);
	}

	public void pushMsg(OrgPushMsgModel model) {
		if (model == null) {
			return;
		}

		OrgPushMsgModel ret = (OrgPushMsgModel) ObjUtils.deepCopy(model);
		if (ret == null) {
			logger.warn("deepCopy fail:" + model.toJsonStr());
			return;
		}
		removeUnRetField(ret);
		sendObj("com.push.org.msg", ret);
	}

	private void removeUnRetField(OrgPushMsgModel model) {
		// 设置空后，转成json字符串不包含
		model.setDelTime(null);
		model.setIsDel(null);
		model.setCreateTime(null);
		model.setPushRegex(null);
	}
}
